package com.dex4d.ui.main.model;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.dex4d.R;
import com.dex4d.model.D4DTxLogModel;

/**
 * 作者    LiQingyi
 * 时间    2018/11/5 11:08
 * 文件    dex4d-android
 * 描述
 */
public class TradeResult implements Parcelable {

    public static final int FLAG_BUY = 0;
    public static final int FLAG_SELL = 1;
    public static final int FLAG_REINVEST = 2;
    public static final int FLAG_SWAP = 3;
    public static final int FLAG_WITHDRAW = 4;
    public static final int FLAG_WITHDRAW_ALL = 5;
    public static final int FLAG_APPROVE = 5;
    public static final int FLAG_BUY_REFERRAL = 6; //购买推荐权限
    public static final int FLAG_BUY_SWAP = 7; //购买对倒权限
    public static final int FLAG_TRANSFER = 8; //转账

    public int flag;
    public String flagStr;
    public String hash;
    public String gas;
    public String amount;
    public D4DTxLogModel txLogModel;

    public TradeResult(int flag) {
        this.flag = flag;
    }

    public TradeResult() {

    }

    public void setHash(String hash) {
        this.hash = hash;
    }

    public String getFlag(Context context) {
        if (flag == FLAG_BUY) {
            return context.getResources().getString(R.string.dex4d_done_buy);
        } else if (flag == FLAG_REINVEST) {
            return "Reinvest";
        } else if (flag == FLAG_SELL) {
            return "Sell";
        } else if (flag == FLAG_SWAP) {
            return "Swap";
        }else if (flag==FLAG_WITHDRAW){
            return "Withdraw";
        }else if (flag==FLAG_WITHDRAW_ALL){
            return "Withdraw All";
        }else if (flag==FLAG_APPROVE){
            return "Approve";
        }else if (flag==FLAG_BUY_REFERRAL) {
            return "Buy_referral";
        }else if (flag==FLAG_BUY_SWAP) {
            return "Buy_swap";
        }else {
            return "Other";
        }
    }

    public String getHash() {
        if (TextUtils.isEmpty(hash)) {
            return hash;
        } else {
            if (hash.length() >= 12) {
                return hash.substring(0, 12) + "..." + hash.substring(hash.length() - 10, hash.length());
            } else {
                return hash;
            }
        }
    }

    public String getGas() {
        return gas;
    }

    public String getAmount() {
        return amount +" Dex4D";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.flag);
        dest.writeString(this.flagStr);
        dest.writeString(this.hash);
        dest.writeString(this.gas);
        dest.writeString(this.amount);
    }

    protected TradeResult(Parcel in) {
        this.flag = in.readInt();
        this.flagStr = in.readString();
        this.hash = in.readString();
        this.gas = in.readString();
        this.amount = in.readString();
    }

    public static final Parcelable.Creator<TradeResult> CREATOR = new Parcelable.Creator<TradeResult>() {
        @Override
        public TradeResult createFromParcel(Parcel source) {
            return new TradeResult(source);
        }

        @Override
        public TradeResult[] newArray(int size) {
            return new TradeResult[size];
        }
    };
}
